<!DOCTYPE html>
<html>

<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0" />
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">
    <title>收货地址管理</title>
    <link type="image/x-icon" rel="shortcut icon" href="../images/favicon.ico">
    <link rel="stylesheet" href="../res/mui/css/mui.min.css" />
    <link rel="stylesheet" href="../res/fontAwesome/css/font-awesome.min.css" />
    <link rel="stylesheet" href="../css/common.css" />
    <link rel="stylesheet" href="../css/user.css" />
    <style>
        select.sel{
        padding: 0 15px;
        box-sizing: border-box;
        color:#666;
    }
    </style>
</head>

<body>
    <div class="cz_layout bgg">
        <header class="cz_topBar">
            <a href="javascript:history.back();" class="icon_back fa fa-arrow-left"></a>
            <span class="title">添加地址</span>
        </header>
        <div class="cz_container">
            <form action="">
                <div class="form_box">
                    <div class="mui-input-row">
                        <input name="recipients" type="text" placeholder="收货人">
                    </div>
                    <div class="mui-input-row">
                        <input name="postcode" type="text" placeholder="邮编">
                    </div>
                    <div class="mui-input-row">
                        <div class="box">
                            <input type="hidden" name="address">
                            <select name="" class="sel" id="p" data-id="">
                                <option value=""> 请选择省份</option>
                                <!-- <optgroup label="请选择省份"></optgroup> -->
                            </select>
                            <select name="" class="sel" id="c" data-id="">
                                <option value=""> 请选择城市</option>
                            </select>
                            <select name="" class="sel" id="d" data-id="">
                                <option value=""> 请选择县区</option>
                            </select>
                        </div>
                    </div>
                    <div class="mui-input-row">
                        <textarea name="addressDetail" id="textarea" rows="5" placeholder="详细地址"></textarea>
                    </div>
                    <button class="mui-btn mui-btn-primary btn_login">确认</button>
                </div>
            </form>
        </div>
        <footer class="cz_tabs">
            <a class="tab_home fa fa-home" href="../index.html"><span>首页</span></a>
            <a class="tab_cate fa fa-bars" href="../cate.html"><span>分类</span></a>
            <a class="tab_cart fa fa-shopping-cart" href="../cart.html"><span>购物车</span></a>
            <a class="tab_user fa fa-user" href="../user/index.html"><span>会员中心</span></a>
        </footer>
    </div>
    <script src="../res/mui/js/mui.min.js"></script>
    <script src="/assets/vendors/jquery/jquery.min.js"></script>
    <script src="/assets/vendors/region/jquery.region.js"></script>
    <script src="/assets/vendors/jquery.form/jquery.form.js"></script>
    <script src="/assets/vendors/layer/layer.js"></script>
    <script>
        //判断用户是否登录
        $.ajax({
            url: "/api/user/queryUserMessage",
            success: function (msg) {
                if (msg.error) return location.href='/user/login.html?url='+location.href;
                $('form').ajaxForm({
                    url: '/api/address/addAddress',
                    type: 'post',
                    //获取 表单之前执行
                    beforeSerialize: function () {
                        var address = '';
                        //因为后台需要具体地址  要找到三级联动信息 并拼接成字符串 赋值隐藏域(input (address))
                        $('form').find('select').each(function () {
                            address += $(this).find('option:selected').text()
                        });
                        $('input[name="address"]').val(address);
                    },
                    success: function (msg) {
                        console.log(msg)

                        if (msg.success) {
                            layer.msg('添加成功', {
                                shift: 5,
                                time: 1000
                            }, function () {
                                location.href = '/user/address.html';
                            })
                        }
                    }

                });
            }
        });
        //省市县三级联动插件调用
        $('.box').region({
            url: '../assets/vendors/region/region.json'
        })
    </script>
</body>

</html>